<template>
	<NavBar :obj="{ title: '店铺', color: '#000', backgroundColor: 'transparent' }" :scrollTop="scrollTop" />

	<image src="/static/bg/bg_dputop.png" mode="widthFix" class="img-top"></image>
	<view class="fill">
		<view class="business flex items-center justify-between">
			<image :src="imgUrl + info.cover" class="logo"></image>
			<view class="middle flex-1">
				<view class="title">{{ info.title }}</view>
				<view class="score flex items-center">
					<view class="item flex items-center">
						<view class="score-title">宝贝质量</view>
						<view class="score-val">{{ info.describe_score }}</view>
					</view>
					<view class="item flex items-center">
						<view class="score-title">物流速度</view>
						<view class="score-val">{{ info.logistics_score }}</view>
					</view>
					<view class="item flex items-center">
						<view class="score-title">服务态度</view>
						<view class="score-val">{{ info.service_score }}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
	<view class="fill-2">
		<view class="cate flex items-center justify-between">
			<view class="items flex items-center flex-1">
				<view :class="{ active: !condition.cate_1 }" class="item" @click="chage('')">全部</view>
				<view :class="{ active: condition.cate_1 == item.id }" class="item" v-for="(item, index) in cate" :key="index" @click="chage(item.id)">{{ item.title }}</view>
			</view>
		</view>

		<Porduct v-model="condition" ref="productRef" />
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	import { port, imgUrl, goUrl, hint, goBack } from '/service/port';
	import { onLoad, onShow } from '@dcloudio/uni-app';
	import Porduct from '/components/Product.vue';

	const id = ref('');
	const info = ref({});
	const cate = ref([]);

	const productRef = ref(null);
	const condition = ref({
		business_id: id,
		cate_1: ''
	});
	onLoad((e) => {
		if (e.id) {
			id.value = e.id;
		}
	});

	onShow(() => {
		getBusinessInfo();
	});

	function chage(id) {
		condition.value.cate_1 = id;
		productRef.value.reload();
	}

	async function getBusinessInfo() {
		let res = await port('getBusinessInfo', { id: id.value });
		info.value = res.data;
		cate.value = res.data.cate;
	}
</script>

<style scoped lang="scss">
	:global(page) {
		background-color: #f0f0f0;
	}
	::v-deep .product-list {
		margin-top: 0 !important;
	}
	.img-top {
		width: 100%;
		height: 378rpx;
		position: absolute;
		top: 0;
		left: 0;
		z-index: 0;
	}
	.fill {
		position: relative;
		margin: 0 30rpx;
		.business {
			background: #ffffff;
			border-radius: 16rpx;
			padding: 30rpx;
			margin-top: 24rpx;
			.logo {
				width: 92rpx;
				height: 92rpx;
			}
			.middle {
				margin-left: 19rpx;
				.title {
					font-weight: 500;
					font-size: 30rpx;
					color: #000000;
				}
				.score {
					margin-top: 15rpx;
					gap: 30rpx;
					.item {
						position: relative;
						&::after {
							content: '';
							display: block;
							width: 1rpx;
							height: 18rpx;
							background: #dbdbdb;
							position: absolute;
							top: 50%;
							right: -11rpx;
							transform: translateY(-50%);
						}
						&:last-child::after {
							display: none;
						}
						.score-title {
							font-weight: 400;
							font-size: 22rpx;
							color: #999999;
						}
						.score-val {
							font-weight: 500;
							font-size: 22rpx;
							color: #333333;
							margin-left: 5rpx;
						}
					}
				}
			}
		}
	}
	.fill-2 {
		.cate {
			position: relative;
			z-index: 1;
			margin-top: 26rpx;
			padding: 30rpx 0 30rpx 30rpx;
			background: linear-gradient(0deg, #f0f0f0 0%, #ffffff 100%);
			.title {
				font-weight: 400;
				font-size: 22rpx;
				color: #ffffff;
			}
			.items {
				gap: 14rpx;
				overflow-x: scroll;
				white-space: nowrap;
				.item {
					background: #f0f0f0;
					border-radius: 28rpx;
					font-weight: 400;
					font-size: 26rpx;
					color: #666666;
					padding: 12rpx 30rpx;
				}
				.active {
					color: #f81a2e;
					background: linear-gradient(90deg, #fde1ef 0%, #fdeeea 100%);
				}
			}
		}
	}
</style>
